from leetcode_test import TreeNode

"""
def 函数A（左树，右树）： 左树节点值等于右树节点值 且 函数A（左树的左子树，右树的右子树），函数A（左树的右子树，右树的左子树）均为真 才返回真
"""


class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        def symmetric(left, right):
            if not left and not right:
                return True
            if not left or not right:
                return False
            return (
                left.val == right.val
                and symmetric(left.left, right.right)
                and symmetric(left.right, right.left)
            )
        if not root:
            return True
        return symmetric(root.left, root.right)


def test():
    t = TreeNode.create([1, 2, 2, 3, 4, 4, 3, 1, 2, 3, 4, 4, 3, 2, 1])
    assert Solution().isSymmetric(t)


if __name__ == "__main__":
    t = TreeNode.create([1,2])
    print(Solution().isSymmetric(t))
